package cn.com.miao.lynx.service.system.repository;

import cn.com.miao.lynx.common.base.repository.BaseRepository;
import cn.com.miao.lynx.service.system.entity.SysRole;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Set;

/**
 * SysRoleRepository
 *
 * @title: SysRoleRepository
 * @description:
 * @author: dengmiao
 * @create: 2020-01-06 15:05
 **/
@Repository
public interface SysRoleRepository extends BaseRepository<SysRole, Long> {

    @Query(value = "SELECT\n" +
            "\tr.id, r.create_by, r.update_by, r.create_time, r.update_time, r.del_status, r.role_code, r.role_name, r.description \n" +
            "FROM\n" +
            "\tsys_role r\n" +
            "\tINNER JOIN sys_user_role ur ON r.id = ur.role_id \n" +
            "\tAND ur.del_status = 0 \n" +
            "WHERE\n" +
            "\tr.del_status = 0 \n" +
            "\tAND ur.user_id = :userId", nativeQuery = true)
    Set<SysRole> findAllByUserId(@Param("userId") Long userId);
}
